<template>
	<view class="env-block">
		<view class="block-title">
			<u-image src="/static/home/icon_env.png" width="38" height="38" />
			<view class="txt">节能减排</view>
		</view>
		<view class="fourth-items">
			<view class="item-block">
				<u-image src="/static/home/icon_co2.png" width="78" height="78" mode="aspectFit" />
				<view class="value-block">{{envData[0]}}</view>
				<view class="unit-name">二氧化碳(万吨)</view>
			</view>
			<view class="item-block">
				<u-image src="/static/home/icon_coal.png" width="78" height="78" mode="aspectFit" />
				<view class="value-block">{{envData[1]}}</view>
				<view class="unit-name">标准煤(万吨)</view>
			</view>
			<view class="item-block">
				<u-image src="/static/home/icon_plainting.png" width="78" height="78" mode="aspectFit" />
				<view class="value-block">{{envData[2]}}</view>
				<view class="unit-name">等效植树(万棵)</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			data: {
				type: String,
				default () {
					return 0
				}
			}
		},
		computed: {
			envData() {
				console.log('计算节能减排=', this.data)
				if (this.data === undefined || this.data === null || this.data === '0') {
					return [0, 0, 0]
				}
				(new RegExp(this.data, "gm"), '')
				let total_power = parseFloat(this.data.replace(new RegExp(',', "gm"), ''))
				//计算公式：co2  累计电量 * 0.997 / 10000  
				let co2 = (total_power * 0.997 / 10000).toFixed(2)
				//标准煤： 累计电量 * 0.4 /10000   
				let coal = (total_power * 0.4 / 10000).toFixed(2)
				//等效植树： 累计电量 * 0.997 / 10000 / 90
				let plant = (total_power * 0.997 / 10000 / 90).toFixed(2)
				return [co2, coal, plant]
			}
		}
	}
</script>

<style lang="scss">
	.env-block {
		padding: 28upx 32upx;

		.fourth-items {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 40upx;
			padding: 0 8upx;

			.item-block {
				display: flex;
				flex-direction: column;
				align-items: center;

				.value-block {
					font-size: 30upx;
					font-weight: bold;
					color: #4290F2;
					margin-top: 10upx;
				}

				.unit-name {
					font-size: 24upx;
					font-weight: 400;
					color: #999999;
					margin-top: 10upx;
					width: 200upx;
					text-align: center;
				}
			}
		}

		.block-title {
			display: flex;
			align-items: center;

			.txt {
				margin-left: 10upx;
				font-weight: 400;
				font-size: 28upx;
				color: #999;
			}
		}
	}
</style>
